import * as express from 'express';
import {
	interfaces,
	controller,
	httpGet,
	httpPost,
	httpDelete,
	queryParam,
	requestParam,
} from 'inversify-express-utils';
import { Container } from 'inversify';
import { makeLabelLogger, lerror, llog } from '../util/logger';
import { Agent } from '../models/Agent';

export default function userControllerFactory(container: Container, applySwaggerMiddlewares) {
	@controller('/agent', ...applySwaggerMiddlewares())
	class Controller implements interfaces.Controller {
		@httpGet('/:id')
		async getObject(@requestParam('id') id, request: express.Request, response: express.Response) {
			try {
				let agent = Agent.getAgent(id);
				llog('get agent', id, agent);
				if (!agent) {
					response.status(404).end();
					return;
				}
				response.json(agent);
			} catch (e) {
				response.status(500).send(e.message);
			}
		}

		@httpPost('/')
		async createObject(request: express.Request, response: express.Response, next: express.NextFunction) {
			try {
				// const agent = Agent.createAgent();
				// agent.start();
				// return agent.id;
			} catch (e) {
				response.status(400).send(e);
				lerror(e);
			}
		}

		@httpDelete('/:id')
		async deleteUser(@requestParam('id') userId, request: express.Request, response: express.Response) {
			try {
				return 'ok';
			} catch (e) {
				response.status(404).send(e.message);
				lerror(e);
			}
		}
	}

	return Controller;
}
